package com.zoagroup.funzy.entity;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * The persistent class for the type_achiev database table.
 * 
 */
@Entity
@Table(name="type_achiev")
public class TypeAchiev implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="id_type_achiev", unique=true, nullable=false)
	private Integer idTypeAchiev;

	private String description;

	//bi-directional many-to-one association to Achievement
	@OneToMany(mappedBy="typeAchievBean", cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	private List<Achievement> achievements;

	public TypeAchiev() {
	}

	public Integer getIdTypeAchiev() {
		return this.idTypeAchiev;
	}

	public void setIdTypeAchiev(Integer idTypeAchiev) {
		this.idTypeAchiev = idTypeAchiev;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Achievement> getAchievements() {
		return this.achievements;
	}

	public void setAchievements(List<Achievement> achievements) {
		this.achievements = achievements;
	}

	public Achievement addAchievement(Achievement achievement) {
		if(achievements == null) {
			achievements = new LinkedList<Achievement>();
		}
		getAchievements().add(achievement);
		achievement.setTypeAchievBean(this);

		return achievement;
	}

	public Achievement removeAchievement(Achievement achievement) {
		if(achievements == null) {
			achievements = new LinkedList<Achievement>();
		}
		getAchievements().remove(achievement);
		achievement.setTypeAchievBean(null);

		return achievement;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((idTypeAchiev == null) ? 0 : idTypeAchiev.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TypeAchiev other = (TypeAchiev) obj;
		if (idTypeAchiev == null) {
			if (other.idTypeAchiev != null)
				return false;
		} else if (!idTypeAchiev.equals(other.idTypeAchiev))
			return false;
		return true;
	}
}